<template>
  <div class="info">
    <template>
      <el-skeleton :loading="loading" />
    </template>
    <template v-if="!loading">
      <el-form :model="searchInfo" inline>
        <el-form-item>
          <el-input clearable v-model="searchInfo.name" placeholder="请输入商户名"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="getList">查询</el-button>
          <el-button icon="el-icon-refresh-right" @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
      <el-form inline>
        <el-form-item>
          <el-button type="success" icon="el-icon-folder-add" @click="openWin()">添加</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="infoList" border>
        <el-table-column type="expand">
          <template slot-scope="scope">
            <el-form class="table-form" inline label-position="left" label-width="100px">
              <el-row>
                <el-col :span="8">
                  <el-form-item label="编号:">
                    <span>{{scope.row.id}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="商户名:">
                    <span>{{scope.row.name}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="地址:">
                    <span>{{scope.row.address}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="介绍:">
                    <span>{{scope.row.description}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="联系方式:">
                    <span>{{scope.row.phone}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="宣传标语:">
                    <span>{{scope.row.promotion_info}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="商户分类:">
                    <span>{{scope.row.category}}</span>
                  </el-form-item>
                </el-col><el-col :span="8">
                <el-form-item label="配送费:">
                  <span>{{scope.row.float_delivery_fee}}</span>
                </el-form-item>
              </el-col>
                <el-col :span="8">
                  <el-form-item label="起送价格:">
                    <span>{{scope.row.float_minimum_order_amount}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="开始营业时间:">
                    <span>{{scope.row.opening_hours[0].split('/')[0]}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="结束营业时间:">
                    <span>{{scope.row.opening_hours[0].split('/')[1]}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="商户门面:">
                    <el-image style="height: 100px;width: 100px" fit="fill" :src="'http://192.168.26.105:8082/file/getImgStream?fileName='+scope.row.image_path"></el-image>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="商户名" prop="name"/>
        <el-table-column label="联系方式" prop="phone"/>
        <el-table-column label="口号" prop="promotion_info" show-overflow-tooltip/>
        <el-table-column label="商户分类" prop="category" />
        <el-table-column label="操作" width="150px">
          <template slot-scope="scope">
            <el-button type="success" size="small" @click="openWin(scope.row)">修改</el-button>
            <el-button type="danger" size="small" @click="delInfo(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination layout="total,prev,pager,next,sizes,jumper"
                     :total="pageInfo.total"
                     :page-size="pageInfo.size"
                     :current-page="pageInfo.current"
                     :page-sizes="[5,10,20,30,50,100]"
                     @size-change="sizeChange"
                     @current-change="currentChange"
      />
    </template>
  </div>
</template>
<script>
export default {
  name: 'listShop',
  data () {
    return {
      loading: true,
      searchInfo: {
        name: '',
        page: 1,
        limit: 5
      },
      infoList: [],
      pageInfo: {}
    }
  },
  methods: {
    getList () {
      this.$http.get('shopping/listShop', this.searchInfo).then(({ data }) => {
        this.loading = false
        if (data.code === 20000) {
          this.infoList = data.data.records
          this.pageInfo = data.data
        }
      })
    },
    sizeChange (limit) {
      this.searchInfo.limit = limit
      this.getList()
    },
    currentChange (page) {
      this.searchInfo.page = page
      this.getList()
    },
    openWin (info) {
      if (info) {
        this.$router.push('addShop6?id=' + info.id)
      } else {
        this.$router.push('addShop')
      }
    },
    delInfo (id) {
      this.$confirm('确定删除该数据吗？', '询问').then(() => {
        this.$axios.delete('shopping/restaurants/' + id).then(({ data }) => {
          if (data.code === 20000) {
            this.$message({
              message: '删除成功',
              type: 'success',
              onClose: () => {
                this.getList()
              }
            })
          } else {
            this.$alert('删除失败！', { type: 'error' })
          }
        })
      })
    },
    resetForm () {
      this.searchInfo.account = ''
      this.searchInfo.name = ''
      this.getList()
    }
  },
  created () {
    this.$nextTick(() => {
      this.getList()
    })
  }
}
</script>

<style scoped lang="scss">

</style>
